/**
* @Title: caseAuditList_Ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('ProblemResearchListCtrl', ['$scope','$http','$modal','CaseAuditListService',
	                                           'BaseURL','Modal','FwaTabsetService','CommunityService','InsuranceService',
	                                function($scope,$http,$modal,caseAuditListService,
	                                		baseUrl,Modal,fwaTabsetService,CommunityService,InsuranceService){
		
		$scope.addOnClick = function(){
			fwaTabsetService.selectTab('caseAudit.caseAuditAdd',null,false);
		}
		
		InsuranceService.initMedicalOrgInfoList().success(function(response){
            $scope.medicalOrgInfoList = response.medicalOrgList;
		});
		
		$scope.communityService = CommunityService;
		CommunityService.getBaseCode('{codeType:\'auditSourceType\'}');

		
		$scope.columns = [
  		{
			label : '事件号',
			map : 'problemCode',
			width : '10%',
			 cellTemplate:'<a  ng:bind="data.problemCode" '+
			 	'ng-click="queryByProblemCode(data)"></a>'}, 
		{
			label : '事件时间段',
			map : 'periodDate',
			width : '15%'
		}, {
			label : '事件要点',
			map : 'keyPoint',
			width : '20%'
		}, {
			label : '来源方式',
			map : 'sourceType',
			width : '10%'
		}, {
			label : '提交日期',
			map : 'submitDate',
			width : '15%'
		}, {
			label : '关联案件号',
			map : 'caseCode',
			width : '15%'
		}, {
			label : '状态',
			map : 'statusName',
			width : '10%'
		}, {
			label : '操作',
			map : 'operation',
			width : '5%',
			cellTemplate:'<a  ng:bind="data.operation" '+
	 		'ng-click="operation(data)"></a>'}];
		
		$scope.operation = function(data){
			if(data.problemStatus ==4 ){
				fwaTabsetService.selectTab('auditDispatchResult',{problemNo:data.problemCode},false);
			}else if(data.problemStatus == 5 ){
				fwaTabsetService.selectTab('auditDispatchReviewResult',{problemNo:data.problemCode},false);
			}else{
				fwaTabsetService.selectTab('auditDispatchReviewDetailResult',{problemNo:data.problemCode},false);
			}
		}
		
		$scope.queryByProblemCode = function(data){
			fwaTabsetService.selectTab('problemDetailView.detail',{problemCode:data.problemCode,problemStatus:data.problemStatus},false);
		}
		
		
        /**
         * 稽核
         * @param data
         */
        $scope.projectAudit = function(data){
            fwaTabsetService.selectTab('caseAuditProject',{problemNo:data},false);
        }
        /**
         * 调查
         * @param data
         */
		$scope.dealPorblemNo = function(data){
			fwaTabsetService.selectTab('auditDispatchResult',{problemNo:data},false);
		}
        /**
         * 复核
         * @param data
         */
        $scope.reviewProblemNo = function(data){
            fwaTabsetService.selectTab('auditDispatchReviewResult',{problemNo:data},false);
        }
        /**
         * 查看复核详情
         * @param data
         */
        $scope.reviewProblemNoDetail = function(data){
            fwaTabsetService.selectTab('auditDispatchReviewDetailResult',{problemNo:data},false);
        }
        /**
         * 查看调查详情
         * @param data
         */
        $scope.dealPorblemNoDetail = function(data){
            fwaTabsetService.selectTab('auditDispatchDetailResult',{problemNo:data},false);
        }
		
		$scope.onReset = function(){
	        	$scope.params.orgName=null;
	        	$scope.params.orgCode=null;
	        	$scope.params.doctorName=null;
	        	$scope.params.jobLicense=null;
	        	$scope.params.sourceType=null;
	        	$scope.params.sbmitDate={start:null,end:null};
	        };
	        
        $scope.params = {
                page:"0",
                pageSize:"20"
            };
        
        /**
	     * 
	     **/
	    $scope.onSubmit = function(){
	    	var fparam = $scope.params;
	    	if($scope.params.sbmitDate){
		    	var start = $scope.params.sbmitDate.start;
		    	var end = $scope.params.sbmitDate.end;
		    	fparam.start = start;
		    	fparam.end = end;
	    	}
	    	if(fparam.orgName=='') { 
	    		fparam.orgName=null;
    		}          
	    	if(fparam.orgCode=='') { 
	    		fparam.orgCode=null;
    		}          
	    	if(fparam.doctorName=='') { 
	    		fparam.doctorName=null;
    		}        
	    	if(fparam.jobLicense=='') { 
	    		fparam.jobLicense=null;
    		}        
	    	if(fparam.sourceType=='') { 
	    		fparam.sourceType=null;
    		}        
	    	fparam.problemStatus ="\'4\',\'5\'";
	    	caseAuditListService.query(fparam).success(function(rst){
	    		if(rst){
            		$scope.tableData = rst.result;
        			$scope.totalCount = rst.totals.total;
	    		}
	    	});
	    }
	    
	    $scope.onSubmit();
	// end line	
	}]);
})();
